﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ThuVienTNN;

namespace KhoTNN
{
    public partial class frmHangHoa : Form
    {
        public frmHangHoa()
        {
            InitializeComponent();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            if (Parent != null) ThuVienTNN.showTab.CloseCurrentTabPage(this.Parent);
            else this.Close();
        }

        private void frmHangHoa_Load(object sender, EventArgs e)
        {
            CauHinhGrid.CauHinh(grvKhachHang , false, true, false, false, true, true);
            CauHinhGrid.HinhDangCot(grvKhachHang, new []{colTenDayDu });
            CauHinhGrid.CauHinhLuaChon(grvKhachHang, DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect, false , true );
            HienThiHangHoa();

            CauHinhGrid.CauHinh(grvHang, true, false, false, false, true, true);
            CauHinhGrid.HinhDangCot(grvHang, new[] { colTenDayDu ,colTenHang ,colTenTat },  DevExpress.Utils.HorzAlignment.Near);
            CauHinhGrid.HinhDangCot(grvHang, new[] { colKichCo, colTheTich, colTheTichTB }, DevExpress.Utils.HorzAlignment.Far);
            CauHinhGrid.CauHinhLuaChon(grvHang , DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect, false, true);
           
        }

        private void HienThiHangHoa()
        {
            var db = new Context();
            dmKhachBindingSource.DataSource = (from p in db.Dm_Khaches select p).ToList();
      
        }

        private void grvKhachHang_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle >= 0)
            {
                var row = grvKhachHang.GetFocusedRow() as Dm_Khach;

                if (row != null)
                {
                    var db = new Context();
                    dmHangBindingSource.DataSource = (from p in db.Dm_Hangs where p.MaKh == row.MaKh select p).ToList();
                }
            }
        }

        private void grvHang_DataSourceChanged(object sender, EventArgs e)
        {
            CauHinhGrid.CanChuan(grvHang);
        }
    }
}
